package DynamicProgramming;

import java.io.PrintWriter;
import java.util.Scanner;

class Solver1009
{	int n,k;
	int[] Dyn0,DynNorm;

	public void Input()
	{	Scanner in=new Scanner(System.in);
		n=in.nextInt();k=in.nextInt();
		
		Dyn0=new int[n+1];
		DynNorm=new int[n+1];
	}
	public void Solve()
	{	Dyn0[1]=0;
		DynNorm[1]=k-1;
		for (int i=2;i<=n;i++)
		{	Dyn0[i]=DynNorm[i-1];
			DynNorm[i]=(k-1)*(Dyn0[i-1]+DynNorm[i-1]);
		}
	}
	public void Output()
	{	PrintWriter out=new PrintWriter(System.out);
		out.println(Dyn0[n]+DynNorm[n]);
		out.flush();
	}
	public void main()
	{	Input();
		Solve();
		Output();
	}
}
public class P1009
{	public static void main(String[] args)
	{	Solver1009 solver=new Solver1009();
		solver.main();
	}
}
